package com.per.mybootall.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: yyy
 * Date: 2022/3/28
 * Time: 10:31
 * Description:失败的构造树
 */
public class test16 {

  public static void main(String[] args) {
    List<Map> initList=init();
    System.out.println("初始数据："+initList.toString());


    initList= builderTree(initList,initList);
    System.out.println("结束数据："+initList.toString());
  }

  public static List<Map> builderTree(List<Map> startDataList,List<Map> endDataList){
    for (Map startData : startDataList) {
      for (Map endData : endDataList) {
        List<Integer> subviewsList=(List<Integer>) endData.get("subviews");
        if(subviewsList.contains(Integer.valueOf(startData.get("top").toString()))){
          startData.put("father",endData);
          List<Map> newEndData=new ArrayList(){{addAll(endDataList);}};
          newEndData.remove(endData);
          builderTree(startDataList,newEndData);
        }else{
          continue;
        }
      }
    }
    return startDataList;
  }


  public static List<Map> init(){
    List<Map> finalList=new ArrayList<>();
    for(int i=1;i<7;i++){
      Map itemMap=new HashMap();
      itemMap.put("has",i);
      itemMap.put("top",i);
      itemMap.put("left",i);
      int finalI = i;
      itemMap.put("subviews",new ArrayList(){{
        switch (finalI){
          case 1: add(2);break;
          case 2: add(3);add(4);add(5);break;
          case 3: add(6);break;
        }
      }});
      finalList.add(itemMap);
    }

    return finalList;
  }
}

